% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
  ignorenonframetext,
]{beamer}
\usepackage{pgfpages}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbolsempty
% Prevent slide breaks in the middle of a paragraph
\widowpenalties 1 10000
\raggedbottom
\setbeamertemplate{part page}{
  \centering
  \begin{beamercolorbox}[sep=16pt,center]{part title}
    \usebeamerfont{part title}\insertpart\par
  \end{beamercolorbox}
}
\setbeamertemplate{section page}{
  \centering
  \begin{beamercolorbox}[sep=12pt,center]{part title}
    \usebeamerfont{section title}\insertsection\par
  \end{beamercolorbox}
}
\setbeamertemplate{subsection page}{
  \centering
  \begin{beamercolorbox}[sep=8pt,center]{part title}
    \usebeamerfont{subsection title}\insertsubsection\par
  \end{beamercolorbox}
}
\AtBeginPart{
  \frame{\partpage}
}
\AtBeginSection{
  \ifbibliography
  \else
    \frame{\sectionpage}
  \fi
}
\AtBeginSubsection{
  \frame{\subsectionpage}
}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\usetheme[]{CambridgeUS}
\usecolortheme{dolphin}
\usefonttheme{serif}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\newif\ifbibliography
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
\usepackage{caption}
% Make caption package work with longtable
\makeatletter
\def\fnum@table{\tablename~\thetable}
\makeatother
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage{ctex}
\usepackage{actuarialsymbol}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={Ch2 生命表与剩余寿命},
  pdfauthor={滕帆},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{Ch2 生命表与剩余寿命}
\subtitle{R语言实验}
\author{滕帆}
\date{2023-09}
\institute{浙大宁波理工学院金融学系}

\begin{document}
\frame{\titlepage}

\begin{frame}[allowframebreaks]
  \tableofcontents[hideallsubsections]
\end{frame}
\hypertarget{ux4ebaux53e3ux6570ux636e}{%
\section{人口数据}\label{ux4ebaux53e3ux6570ux636e}}

\begin{frame}{人口数据}
以第七次全国人口普查为例，资料来源:
\href{http://www.stats.gov.cn/sj/pcsj/rkpc/7rp/zk/indexce.htm}{中国人口普查年鉴}

\begin{itemize}
\tightlist
\item
  原始数据：全国分年龄、性别的死亡人口状况节选
\item
  性别人口
\item
  性别比
\item
  分年龄死亡率
\end{itemize}
\end{frame}

\begin{frame}[fragile]{全国分年龄、性别的死亡人口状况节选(2019.11.1-2020.10.31)}
\protect\hypertarget{ux5168ux56fdux5206ux5e74ux9f84ux6027ux522bux7684ux6b7bux4ea1ux4ebaux53e3ux72b6ux51b5ux8282ux90092019.11.1-2020.10.31}{}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{mort }\OtherTok{\textless{}{-}} \FunctionTok{read\_excel}\NormalTok{(}\StringTok{"mortality2020.xls"}\NormalTok{)}
\NormalTok{mort }\SpecialCharTok{|\textgreater{}} \FunctionTok{select}\NormalTok{(age, pop, pop\_women, mortality\_women)}\SpecialCharTok{|\textgreater{}} 
  \FunctionTok{filter}\NormalTok{(age}\SpecialCharTok{\textgreater{}=}\DecValTok{20} \SpecialCharTok{\&}\NormalTok{ age}\SpecialCharTok{\textless{}=}\DecValTok{30}\NormalTok{) }\SpecialCharTok{|\textgreater{}}
  \FunctionTok{kable}\NormalTok{()}
\end{Highlighting}
\end{Shaded}

\begin{longtable}[]{@{}rrrr@{}}
\toprule\noalign{}
age & pop & pop\_women & mortality\_women \\
\midrule\noalign{}
\endhead
20 & 14400615 & 6758569 & 0.20 \\
21 & 14687059 & 6901256 & 0.20 \\
22 & 15042526 & 7084524 & 0.22 \\
23 & 15713815 & 7415774 & 0.21 \\
24 & 16797188 & 7940021 & 0.22 \\
25 & 16856809 & 7979257 & 0.22 \\
26 & 17272911 & 8212659 & 0.22 \\
27 & 18652195 & 8879589 & 0.23 \\
28 & 19735216 & 9408476 & 0.24 \\
29 & 23227736 & 11137359 & 0.24 \\
30 & 26223230 & 12690592 & 0.26 \\
\bottomrule\noalign{}
\end{longtable}
\end{frame}

\begin{frame}{性别人口}
\protect\hypertarget{ux6027ux522bux4ebaux53e3}{}
\includegraphics{ch2code_files/figure-beamer/unnamed-chunk-2-1.pdf}
\end{frame}

\begin{frame}{性别比}
\protect\hypertarget{ux6027ux522bux6bd4}{}
\includegraphics{ch2code_files/figure-beamer/unnamed-chunk-3-1.pdf}
\end{frame}

\begin{frame}{分年龄死亡率}
\protect\hypertarget{ux5206ux5e74ux9f84ux6b7bux4ea1ux7387}{}
\begin{columns}[T]
\begin{column}{0.65\textwidth}
\includegraphics{ch2code_files/figure-beamer/unnamed-chunk-4-1.pdf}
\end{column}

\begin{column}{0.35\textwidth}
\begin{longtable}[]{@{}rr@{}}
\toprule\noalign{}
age & mortality \\
\midrule\noalign{}
\endhead
20 & 0.31 \\
21 & 0.32 \\
22 & 0.33 \\
23 & 0.33 \\
24 & 0.35 \\
25 & 0.37 \\
26 & 0.37 \\
27 & 0.39 \\
28 & 0.41 \\
29 & 0.41 \\
30 & 0.44 \\
\bottomrule\noalign{}
\end{longtable}
\end{column}
\end{columns}
\end{frame}

\hypertarget{ux56fdux6c11ux751fux547dux8868}{%
\section{国民生命表}\label{ux56fdux6c11ux751fux547dux8868}}

\begin{frame}{国民生命表}
\begin{enumerate}
\item
  普查死亡率转换为生命表(life table)
\item
  基于生命表进行必要的计算
\end{enumerate}
\end{frame}

\begin{frame}[fragile]{死亡率转换为生命表}
\protect\hypertarget{ux6b7bux4ea1ux7387ux8f6cux6362ux4e3aux751fux547dux8868}{}
\begin{itemize}
\tightlist
\item
  首先加载\texttt{library(lifecontingencies)}
\item
  应用\texttt{probs2lifetable}函数
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{lt.cn}\OtherTok{\textless{}{-}}\FunctionTok{probs2lifetable}\NormalTok{(mort}\SpecialCharTok{$}\NormalTok{mortality}\SpecialCharTok{/}\DecValTok{1000}\NormalTok{,}
                       \AttributeTok{radix=}\DecValTok{10}\SpecialCharTok{\^{}}\DecValTok{5}\NormalTok{,}\AttributeTok{type=}\StringTok{"qx"}\NormalTok{,}
                       \AttributeTok{name=}\StringTok{"life table 2020"}\NormalTok{)}
\FunctionTok{print}\NormalTok{(lt.cn)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Life table life table 2020 
## 
##       x         lx      px        ex
## 1     0 100000.000 0.99847 80.786288
## 2     1  99847.000 0.99961 79.910081
## 3     2  99808.060 0.99974 78.941258
## 4     3  99782.110 0.99980 77.961788
## 5     4  99762.153 0.99982 76.977383
## 6     5  99744.196 0.99984 75.991242
## 7     6  99728.237 0.99986 75.003402
## 8     7  99714.275 0.99987 74.013904
## 9     8  99701.312 0.99987 73.023527
## 10    9  99688.351 0.99987 72.033021
## 11   10  99675.391 0.99986 71.042387
## 12   11  99661.437 0.99985 70.052334
## 13   12  99646.488 0.99983 69.062844
## 14   13  99629.548 0.99978 68.074586
## 15   14  99607.629 0.99976 67.089566
## 16   15  99583.723 0.99973 66.105671
## 17   16  99556.836 0.99972 65.123525
## 18   17  99528.960 0.99972 64.141764
## 19   18  99501.092 0.99969 63.159729
## 20   19  99470.246 0.99971 62.179315
## 21   20  99441.400 0.99969 61.197352
## 22   21  99410.573 0.99968 60.216329
## 23   22  99378.762 0.99967 59.235604
## 24   23  99345.967 0.99967 58.255159
## 25   24  99313.183 0.99965 57.274389
## 26   25  99278.423 0.99963 56.294442
## 27   26  99241.690 0.99963 55.315279
## 28   27  99204.971 0.99961 54.335753
## 29   28  99166.281 0.99959 53.356952
## 30   29  99125.623 0.99959 52.378838
## 31   30  99084.981 0.99956 51.400322
## 32   31  99041.384 0.99953 50.422948
## 33   32  98994.834 0.99951 49.446658
## 34   33  98946.327 0.99944 48.470899
## 35   34  98890.917 0.99940 47.498057
## 36   35  98831.582 0.99935 46.526573
## 37   36  98767.342 0.99930 45.556835
## 38   37  98698.205 0.99923 44.588748
## 39   38  98622.207 0.99917 43.623107
## 40   39  98540.351 0.99905 42.659345
## 41   40  98446.737 0.99900 41.699909
## 42   41  98348.290 0.99886 40.741651
## 43   42  98236.173 0.99876 39.788150
## 44   43  98114.361 0.99864 38.837548
## 45   44  97980.925 0.99852 37.890439
## 46   45  97835.913 0.99837 36.946600
## 47   46  97676.441 0.99824 36.006921
## 48   47  97504.530 0.99809 35.070405
## 49   48  97318.297 0.99794 34.137518
## 50   49  97117.821 0.99773 33.207986
## 51   50  96897.363 0.99750 32.283540
## 52   51  96655.120 0.99733 31.364451
## 53   52  96397.051 0.99693 30.448418
## 54   53  96101.112 0.99671 29.542183
## 55   54  95784.939 0.99648 28.639698
## 56   55  95447.776 0.99613 27.740865
## 57   56  95078.393 0.99578 26.848640
## 58   57  94677.162 0.99549 25.962421
## 59   58  94250.168 0.99468 25.080042
## 60   59  93748.758 0.99447 24.214182
## 61   60  93230.327 0.99379 23.348831
## 62   61  92651.367 0.99325 22.494733
## 63   62  92025.970 0.99278 21.647604
## 64   63  91361.542 0.99195 20.805037
## 65   64  90626.082 0.99115 19.973876
## 66   65  89824.041 0.99051 19.152223
## 67   66  88971.611 0.98938 18.335719
## 68   67  88026.732 0.98832 17.532535
## 69   68  86998.580 0.98665 16.739735
## 70   69  85837.149 0.98545 15.966234
## 71   70  84588.219 0.98381 15.201973
## 72   71  83218.735 0.98131 14.452143
## 73   72  81663.377 0.97944 13.727398
## 74   73  79984.378 0.97721 13.015558
## 75   74  78161.534 0.97471 12.319100
## 76   75  76184.829 0.97111 11.638734
## 77   76  73983.849 0.96835 10.984980
## 78   77  71642.261 0.96452 10.344018
## 79   78  69100.393 0.96033  9.724524
## 80   79  66359.181 0.95473  9.126232
## 81   80  63355.100 0.94939  8.558966
## 82   81  60148.699 0.94349  8.015227
## 83   82  56749.696 0.93588  7.495296
## 84   83  53110.905 0.92870  7.008822
## 85   84  49324.098 0.92232  6.546917
## 86   85  45492.602 0.91292  6.098314
## 87   86  41531.106 0.90547  5.680009
## 88   87  37605.171 0.89140  5.272996
## 89   88  33521.249 0.88477  4.915409
## 90   89  29658.596 0.87377  4.555578
## 91   90  25914.791 0.85610  4.213704
## 92   91  22185.653 0.84401  3.921977
## 93   92  18724.913 0.83213  3.646837
## 94   93  15581.562 0.81931  3.382532
## 95   94  12766.129 0.80837  3.128513
## 96   95  10319.756 0.79948  2.870150
## 97   96   8250.438 0.79328  2.590021
## 98   97   6544.908 0.78755  2.264952
## 99   98   5154.442 0.78297  1.875947
## 100  99   4035.774 0.79199  1.395938
## 101 100   3196.292 0.76257  0.762570
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{基本计算\texttt{pxt()}、\texttt{qxt()}}
\protect\hypertarget{ux57faux672cux8ba1ux7b97pxtqxt}{}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{pxt}\NormalTok{(lt.cn,}\AttributeTok{x=}\DecValTok{20}\NormalTok{,}\AttributeTok{t=}\DecValTok{10}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 0.9964158
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{qxt}\NormalTok{(lt.cn,}\AttributeTok{x=}\DecValTok{20}\NormalTok{,}\AttributeTok{t=}\DecValTok{10}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 0.003584212
\end{verbatim}
\end{frame}

\end{document}
